from pyecharts import Scatter,Scatter3D
import  random
import math
import numpy as np
from pyecharts import Page
import  time

#[x1=rand(),x2=rand(),x3=50+40*sin(x1)]

mode = False
#mode = True

wave = 10 # 数据波动范围
min = 0  # 最小
max = 99  # 最大
cnts = 100 # 数据量
size = 3  # DIMENSION
Intval = 3

def genx1():
    return int((random.randint(0,1))*50+(max-min)/4)
def genx2():
    return int((random.randint(0,1))*50+(max-min)/4)
def genx3():
    return int((random.randint(0,1))*50+(max-min)/4)
def _wave():
    return random.randint(-wave, wave)
def rawdata():
    if mode is  True:
        data = np.load("rawdata.npy")
    else:

        data = np.zeros((cnts,size),np.int16)
        for i in range(cnts):
            rate = (max-min-2*wave)/(max-min)
            data[i][0] = genx1()+_wave()
            data[i][1] =  genx1()+_wave()
            if(size>=3):
                data[i][2] =  genx1()+_wave()
            print(data[i])
        np.save("rawdata.npy",data)
    return data

def show3dscatter(data):


    scatter =  Scatter3D("初始散点图",width=1000,height=800)
    scatter.add("0",data)

    scatter.render("rawdata.html")
    pass
def show2dscatter(data):
    scatter = Scatter("初始散点图", width=1000, height=800)
    scatter.add("0", data[:,0],data[:,1])
    scatter.render("rawdata.html")

def show3dNtime(data,k=3,n=1):
    time.sleep(Intval)
    #data[0] for a group of data
    scatter = Scatter3D("K分类散点图("+n.__str__()+"-th迭代)", width=1000, height=800)
    for _ in range(k):
        scatter.add(""+_.__str__(), data[_])
    scatter.render("retingdata.html")

def show3dRet(data,k=3):
    #data[0] for a group of data
    scatter = Scatter3D("结果散点图)", width=1000, height=800)
    for _ in range(k):
        scatter.add(""+_.__str__(), data[_])
    scatter.render("retdata.html")

def showNtime(data,k=3,n=1):
    #data[0] for a group of data
    scatter = Scatter("K分类散点图("+n.__str__()+"-th迭代)", width=1000, height=800)
    for _ in range(k):
        scatter.add(""+_.__str__(), data[_][:,0],data[_][:,1])
    scatter.render("retingdata.html")

def showRet(data,k=3):
    #data[0] for a group of data
    scatter = Scatter3D("结果散点图)", width=1000, height=800)
    for _ in range(k):
        scatter.add("" + _.__str__(), data[_][:, 0], data[_][:, 1])
    scatter.render("retdata.html")